import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
import 'package:moose_app/core/model/common_item_model.dart';
import 'package:moose_app/core/utils/navigate_util.dart';
import 'package:moose_app/ui/screens/address_receiving/address_receiving_screen.dart';
import 'package:moose_app/ui/screens/sign_in/sign_in_screen.dart';
import 'package:moose_app/ui/values/constants.dart';
import 'package:moose_app/ui/values/values.dart';
import 'package:moose_app/ui/widgets/common/common_list_item.dart';
import 'package:moose_app/ui/widgets/common/common_more_sheet.dart';

import 'widget/mime_order_tip_info.dart';
import 'widget/mime_user_info.dart';
import 'widget/mime_vip_info_tip.dart';

class ATHMimeBody extends StatefulWidget {
  @override
  _ATHMimeBodyState createState() => _ATHMimeBodyState();
}

class _ATHMimeBodyState extends State<ATHMimeBody> {
  List<ATHCommonItemModel> _mimeListItems = [];

  @override
  void initState() {
    _mimeListItems.add(ATHCommonItemModel(title: "签到有礼", type: "sign_in"));
    _mimeListItems.add(ATHCommonItemModel(title: "我点过赞", type: "like"));
    _mimeListItems.add(ATHCommonItemModel(title: "我的收藏", type: "collect"));
    _mimeListItems.add(ATHCommonItemModel(title: "我的团队", type: "team"));
    _mimeListItems.add(ATHCommonItemModel(title: "我的勋章", type: "medal"));
    _mimeListItems.add(ATHCommonItemModel(title: "收货地址", type: "address"));

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return EasyRefresh.custom(
      header: MaterialHeader(),
      onRefresh: () async {},
      slivers: <Widget>[
        SliverToBoxAdapter(
          child: ATHMimeUserInfo(press: _chooseAvatarImage),
        ),
        SliverToBoxAdapter(
            child: Container(
                margin: EdgeInsets.symmetric(vertical: kSize20),
                child: ATHMimeVipInfoTip())),
        SliverToBoxAdapter(child: ATHMimeOrderTipInfo()),
        SliverList(
            delegate: SliverChildBuilderDelegate((ctx, index) {
          ATHCommonItemModel model = _mimeListItems[index];
          return ATHCommonListItem(
            title: Text(
              model.title,
              style: TextStyle(color: kColor33, fontSize: kFontSize32),
            ),
            showDivider: index != _mimeListItems.length - 1,
            press: () {
              _handleMimeItemPress(model);
            },
          );
        }, childCount: _mimeListItems.length)),
      ],
    );
  }

  void _handleMimeItemPress(ATHCommonItemModel model) {
    switch (model.type) {
      case "sign_in":
        ATHNavigator.pushFromRight(context, ATHSignInScreen.routeName);
        break;
      case "address":
        ATHNavigator.pushFromRight(
            context, ATHAddressReceivingScreen.routeName);
        break;
      default:
        showCupertinoModalBottomSheet(
          expand: false,
          context: context,
          backgroundColor: Colors.transparent,
          builder: (BuildContext context) {
            return ATHCommonMoreSheet();
          },
        );
        break;
    }
  }

  void _chooseAvatarImage() async {
//    final pickedFile = await _imagePicker.getImage(source: ImageSource.gallery);
//    print(pickedFile.path);
//    this.setState(() {
//      _imageFile = pickedFile;
//    });
  }
}
